package com.stone.mythread;

import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Data
public class NullTest {

    School sc2 = School.builder()
            .scId(1001)
            .myClass(MyClass.builder()
                    .myCId(2001)
                    .student(Student.builder()
                            .stId(3001)
                            .name("张三")
                            .build())
                    .build())
            .build();

    public static void main(String[] args) {
        List<School> schools = new ArrayList<>();
        School sc1 = School.builder()
                .scId(1001)
                .myClass(MyClass.builder()
                        .myCId(2001)
                        .student(Student.builder()
                                .stId(3001)
                                .name("张三")
                                .build())
                        .build())
                .build();

        String name = Optional.ofNullable(sc1)
                .map(School::getMyClass)
                .map(MyClass::getStudent)
                .map(Student::getName)
                .orElse(null);
        System.err.println(State.NEW);
    }

}

@Builder
@Data
class School {

    Integer scId;

    MyClass myClass;
}

@Builder
@Data
class MyClass {

    Integer myCId;

    Student student;
}

@Builder
@Data
class Student {

    Integer stId;

    String name;

}

enum State {
    NEW,
    END;
}
